cap log close 
log using "${logpath}general_deterrence.log", replace

/*******************************************************************************
general_deterrence.do

Investigates effect of enforcement capacity
*******************************************************************************/

qui {
	use "${cleandatapath}dist_data.dta", clear

	bysort dist_code: egen mode_dist=mode(district)
	replace district=mode_dist

	replace year=year(dofm(month_date))

	collapse (sum) ambulance_id tot_pmt (mean) prior_auth post_crim post_civ, by(district year)

	replace district="Delaware" if district=="Deleware"
	replace district="Northern Mariana Islands" if district=="American Samoa"

	merge 1:1 district year using ${cleandatapath}WorkHours.dta
	keep if _merge==3

	gen log_rides=log(ambulance_id+1)
	gen log_pmt=log(tot_pmt+1)
	gen log_total=log(Total+1)
	gen log_crim=log(DistrictCourtCriminal+1)
	gen log_civ=log(DistrictCourtCivil+1)

	estimates clear
	eststo: reghdfe log_pmt log_civ, a(district year) cluster(district)
		eststo est1,addscalars(Year_FE 1)
		eststo est1,addscalars(Dist_FE 1)
		estadd ysumm
	eststo: reghdfe log_rides log_civ, a(district year) cluster(district)
		eststo est2,addscalars(Year_FE 1)
		eststo est2,addscalars(Dist_FE 1)
		estadd ysumm
	eststo: reghdfe log_pmt log_crim, a(district year) cluster(district)
		eststo est3,addscalars(Year_FE 1)
		eststo est3,addscalars(Dist_FE 1)
		estadd ysumm
	eststo: reghdfe log_rides log_crim, a(district year) cluster(district)
		eststo est4,addscalars(Year_FE 1)
		eststo est4,addscalars(Dist_FE 1)
		estadd ysumm
	eststo: reghdfe log_pmt log_total, a(district year) cluster(district)
		eststo est5,addscalars(Year_FE 1)
		eststo est5,addscalars(Dist_FE 1)
		estadd ysumm
	eststo: reghdfe log_rides log_total, a(district year) cluster(district)
		eststo est6,addscalars(Year_FE 1)
		eststo est6,addscalars(Dist_FE 1)
		estadd ysumm

	label variable log_civ "Civil Court Hours (Log)"
	label variable log_crim "Criminal Court Hours (Log)"
	label variable log_total "Total Court Hours (Log)"
	label var log_pmt "\shortstack{Total Ride\\ Payments (Log)}"
	label var log_rides "\shortstack{Total\\ Rides (Log)}"

	esttab using ${outpath}Table_9.tex, replace ///
		drop(_cons) lab booktabs frag se ///
		star(+ 0.1 * 0.05 ** 0.01 *** 0.001) ///
		stats(Dist_FE Year_FE ymean N, ///
			label("Month-Year FE" "District FE" "Dep. Var. Mean" "Observations"))
}

di 0.0117-0.105*1.96 // Referenced in Section 5.4, Paragraph 5
di 0.0631-0.191*1.96 // Referenced in Section 5.4, Paragraph 5
		
log close